﻿/* ----------------------------------------------------------------------------
 * Copyright (c) Philip Stears 
 *
 * This source code is subject to terms and conditions of the Microsoft Public 
 * License (Ms-PL).
 * 
 * By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 * 
 * To request a copy of the Microsoft Public License, send a request by email
 * to license@connectbasic.net.
 *
 * This notice must not be removed from this software.
 * ---------------------------------------------------------------------------- */

namespace ConnectBasic.Shell.Implementation
{
    using ConnectBasic.Shell.Extensibility;
    using Microsoft.Scripting;

    /// <summary>
    /// Provides an implementation of the <see cref="ISpan" /> interface
    /// on top of a DLR <see cref="TokenInfo" /> structure.
    /// </summary>
    public class DlrTokenSpan : ISpan
    {
        private TokenInfo mTokenInfo;

        /// <summary>
        /// Initializes a new instance of the <see cref="DlrTokenSpan" />
        /// class.
        /// </summary>
        /// <param name="info">The DLR token info.</param>
        public DlrTokenSpan(TokenInfo info)
        {
            mTokenInfo = info;
        }

        #region ISpan Members

        /// <summary>
        /// The name of the category which describes the span of text.
        /// </summary>
        public string CategoryName
        {
            get { return GetCategoryName(mTokenInfo.Category); }
        }

        /// <summary>
        /// The start index of the span of text.
        /// </summary>
        public int StartIndex
        {
            get { return mTokenInfo.SourceSpan.Start.Index; }
        }

        /// <summary>
        /// The end index of the span of text.
        /// </summary>
        public int EndIndex
        {
            get { return mTokenInfo.SourceSpan.End.Index; }
        }

        #endregion

        #region Private Helpers

        private static string GetCategoryName(TokenCategory category)
        {
            return category.ToString();
        }

        #endregion
    }
}
